<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title>コントロールパネル</title>

    <link href="./assets/styles/default.css" rel="stylesheet" />
	<script src="./assets/scripts/libs/jquery-1.7.1.min.js" type="text/javascript"></script>
	<script src="./assets/scripts/import.js" type="text/javascript"></script>
	<script>
		$(function(){

			var target = $('search_result');
			var cont = $('#selectNum');

			var countSelected = function(){
				var size = $('.checked',search_result).size();
				cont.html(size);
			}

			$('label',search_result).click(function(){
				countSelected();
			});

			$('.ctrlSelect').click(function(){
				var select = $(this).data("d");
				var target = $('input[name=ctrl]');
				if(select == "check"){
					target.attr('checked','checked');
					target.closest("label").addClass("checked");
				} else {
					target.removeAttr('checked');
					target.closest("label").removeClass("checked");
				}
				countSelected();
			});
		});

		function dobatch() {
		if($("input[id='orderchecked']:checked").length==0)
        {
        alert("処理データを選択してください");return false;
        }
			var idlist=new Array();
			var index=0;
			$("input[id='orderchecked']").each(
			function(i,el){

				if($(this).prop("checked"))
				{
					idlist[index]=$(this).attr("orderid");
					index++;
				}
			}
			);
			updatesended(idlist,$("#doselected").val());
		}

		function updatesended(orderids,setstatus) {
		    
			var poststr=orderids.join("-");
			if (setstatus == 3) {
			    top.window.location = "Home_OrderRefer_openupdatesended.html?oid=" + poststr + "&muti=1";

			    return;
			}
			$.ajax({url:"{{'Home/OrderManage/updatesended'|U}}",type:"POST",data: "orderids="+poststr+"&setstatus="+setstatus,
				success: function(msg){
				     if(msg=="cart ajax success")
				    	 {
					    	 for(i=0;i<orderids.length;i++) {

					    		 switch(Number(setstatus))
					    		 {
						    		 case 1:
						    			$('#order_status_'+orderids[i]).html('未確定');
						    			break;
						    		 case 2:
						    			 $('#order_status_'+orderids[i]).html('確定');
						    			 break;
						    		 case 3:
						    			 $('#order_status_'+orderids[i]).html('発送済');
						    			 break;
						    		 case 4:
						    			 $('#order_status_'+orderids[i]).html('キャンセル');
						    			 break;
					    			 default:
					    				 break;
					    		 }
					    	 }
				    	 }
				     else
				    	 {
				    	 alert(msg);
				    	 }
				   },
				error:function(msg)
				{
					alert(msg);
				}
			})

		}

	</script>
	<style>
		.headerCtrl li {
			font-size:14px;
			line-height: 28px;
			margin-right: 10px;
		}
		.headerCtrl li .ctrlSelect {
			color: #399CE8;
		}
	</style>
</head>
<body>

{{$zhead}}
<div id="container">
{{$zmenu}}
<center><span style="color:red;">{{$errmsg}}</span></center>
    <article>
    	<h2><span>&nbsp;</span>注文管理<p><a href="javascript:;">Open Plugins</a></p></h2>
        <nav>
        	<ul>
				<li class="active"><a href="Home_OrderManage_index.html"><span>履歴検索</span></a></li>
				<li><a href="Home_order_summary.html"><span>売上集計</span></a></li>
				<li><a href="Home_order_setting.html"><span>基本設定</span></a></li>
			</ul>
        </nav>

        <section id="content">

        	<h3>注文検索</h3>
			<form method="post" action="{{'Home/OrderManage/search'|U}}" id="form1" name="form1" >
			<div id="search_form">

					<dl>
						<dt>フリーワード</dt>
						<dd>
							<input type="text" name="text_search" value="{{$text_search}}" />
						</dd>
					</dl>
					<dl>
						<dt>状態</dt>
						<dd>
							<label><input type="checkbox" name="check_status1" value="1" {{$check_status1}} />未確定</label>
							<label><input type="checkbox" name="check_status2" value="1" {{$check_status2}} />確定</label>
							<label><input type="checkbox" name="check_status3" value="1" {{$check_status3}} />発送済</label>
							<label><input type="checkbox" name="check_status4" value="1" {{$check_status4}} />キャンセル</label>
						</dd>
					</dl>
					<dl>
						<dt>注文期間</dt>
						<dd>
							<input type="text" name="text_time1" class="text_date" value="{{$text_time1}}" /> ～
							<input type="text" name="text_time2" class="text_date" value="{{$text_time2}}" />
						</dd>
					</dl>
					<dl>
						<dt>経路</dt>
						<dd>
							<label><input type="checkbox" name="check_way1" value="1" {{$check_way1}} />PC</label>
							<label><input type="checkbox" name="check_way2" value="2" {{$check_way2}} />スマホ</label>
						</dd>
					</dl>
					<dl>
						<dt>支払方法</dt>
						<dd>
						{{foreach name=buyingloop from=$buyinglist item=i}}
							<label><input type="checkbox" name="check_buying{{$i.id}}" value="{{$i.id}}" {{if $i.checked eq 1}}checked{{/if}} />{{$i.content}}</label>
						{{/foreach}}
						<!-- <label><input type="checkbox" name="" value="" />代引き</label> -->
						</dd>
					</dl>
					<dl>
						<dt>発送方法</dt>
						<dd>
						{{foreach name=sendloop from=$sendlist item=i}}
							<label><input type="checkbox" name="check_send{{$i.id}}" value="{{$i.id}}"  {{if $i.checked eq 1}}checked{{/if}} />{{$i.content}}</label>
						{{/foreach}}
							<!-- <label><input type="checkbox" name="" value="" />ゆうパック</label> -->
						</dd>
					</dl>
					<dl class="category clear">
						<dt>カテゴリー</dt>
						<dd>
							<p class="btn_blank float-left btn_category" id="id_category">
								<a href="javascript:;">カテゴリ選択</a>
							</p>
							<ul id="search_category" class="float-left">
							</ul>
						</dd>
					</dl>
					<p class="search_submit">
						<button type="submit" class="submit"><span>検索</span></button>
					</p>
					<input type="hidden" name="" value="" />
			</div>
			{{if $indexflag neq 1}}<p class="message">{{if $orderlist|@count eq 0}}見つかりませんでした。{{else}}{{$allcount}}件登録されています。{{/if}}</p>{{/if}}

{{if $orderlist|@count neq 0}}
			<ul class="btns float-right headerCtrl">
				<li>表示件数:</li>
				<li>
					<select name="showNum" id="showNum" onchange="$('form').submit();">
						<option value="5" {{if $showNum eq 5}}selected{{/if}}>5件</option>
						<option value="10" {{if $showNum eq 10}}selected{{/if}}>10件</option>
						<option value="20" {{if $showNum eq 20}}selected{{/if}}>20件</option>
						<option value="50" {{if $showNum eq 50}}selected{{/if}}>50件</option>
					</select>
				</li>
			</ul>
			<ul class="btns b10 headerCtrl">
				<li>
					<a href="javascript:;" class="ctrlSelect" data-d="check">全選択</a>
					&nbsp;|&nbsp;
					<a href="javascript:;" class="ctrlSelect" data-d="uncheck">選択解除</a>
				</li>
				<li>選択件数:<b id="selectNum">0</b>件</li>
				<li>
					<select  id="doselected">
						<option value="1">未確定処理</option>
						<option value="2">確定処理</option>
						<option value="3" selected>配送完了処理</option>
						<option value="4">キャンセル処理</option>
					</select>
				</li>
				<li class="btn single c" style="position: relatve;top:-2px;left:-10px;"><a href="#" onclick="dobatch();return false;">実行</a></li>
			</ul>
			<table id="search_result" class="sortable">
				<thead>
					<tr>
						<th class="align-center">処理</th>
						<th class="align-center">注文日時<br />注文番号</th>
						<th>状態<br />経路</th>
						<th>購入者氏名</th>
						<th>配送先住所</th>
						<th>支払方法<br />発送方法</th>
						<th>合計金額<br />手数料</th>
						<th>更新</th>
						<th>配送完了</th>
					</tr>

				</thead>
				<tbody>
					{{foreach name=orderloop from=$orderlist item=i}}
					<tr>
						<td><label><input type="checkbox" name="ctrl" value="" id="orderchecked" orderid="{{$i.order_id}}"/></label></td>
						<td class="align-left">{{$i.order_time|date_format:"%Y-%m-%d %H:%M:%S"}}<br />{{$i.order_number}}</td>
						<td ><span id="order_status_{{$i.order_id}}">{{if $i.order_status eq 1}}未確定{{elseif $i.order_status eq 2}}確定{{elseif $i.order_status eq 3}}発送済{{elseif $i.order_status eq 4}}キャンセル{{/if}}</span><br />{{if $i.order_way eq 1}}PC{{elseif $i.order_way eq 2}}スマホ{{/if}}</td>
						<td>{{$i.user_name1|cat:$i.user_name2}}</td>
						<td>{{$i.send_local_name|cat:" "|cat:$i.send_treet_name|cat:" "|cat:$i.send_address}}</td>
						<td>{{$i.pay_content}}<br />{{$i.send_content}}</td>
						<td class="align-right">{{$i.sumprice|string_format:"%.0f"}}円<br />{{$i.buying_price|string_format:"%.0f"}}円</td>
						<td class="update"><a href="{{'Home/OrderRefer/index'|U}}?oid={{$i.order_id}}">更新</a></td>
						<td class="preview"><a href="#" onclick="updatesended([{{$i.order_id}}],3);return false;">発送完了</a></td>
					</tr>
					{{/foreach}}
				</tbody>
			</table>
			<input type="hidden" name="nowpage" id="nowpage" value="{{$nowpage}}">
			<script type="text/javascript">
			function aclick(ipage)
			{
				$('#nowpage').val(ipage);
				$('#form1').attr('action','{{'Home/OrderManage/changepage'|U}}');
				document.getElementById("form1").submit();
			}
			</script>
			<p class="pageNav">
				{{section name=loop loop=$pagecount}}
				<a href="#" onclick="aclick({{$smarty.section.loop.index+1}});return false;" {{if $smarty.section.loop.index+1 eq $nowpage}}class="current"{{/if}}>{{$smarty.section.loop.index+1}}</a>
				{{/section}}
				<!-- <a href="" class="current">1</a>
				<a href="">2</a>
				<a href="">3</a> -->
			</p>

			<p class="btn_dl float-right">
				<a href="javascript:;" onclick="csv_download();">
					CSVダウンロード
				</a>
			</p>
			{{/if}}
</form>
        </section>
    </article>


</div>

<footer id="dashboard_footer">Copyright (C) SHIFT. / All rights reserved.</footer>
</body>
</html>